﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ChatApp.Service.Model;
//using ChatApp.Service.Model;

namespace ChatApp.Service.Business
{
    public class AddFriendBLL
    {
        /// <summary>
        /// Taọ người dùng
        /// </summary>
        /// <param name="user"></param>
        public int CreateAddFriend(AddFriend addFriend)
        {
            int idAddFriend = 0;
            using (DBChatEntities entities = new DBChatEntities())
            {
                addFriend.NgayTao = DateTime.UtcNow;
                entities.AddFriends.AddObject(addFriend);
                idAddFriend = entities.SaveChanges();
            }
            return idAddFriend;
        }

        /// <summary>
        /// Lấy danh sách bạn bè của người đăng nhập
        /// </summary>
        /// <param name="idUser"></param>
        /// <returns></returns>
        public List<AddFriend> RetrieveAllAddFriend(string userName)
        {
            List<AddFriend> listAddFriend = new List<AddFriend>();
            using (DBChatEntities entities = new DBChatEntities())
            {
                listAddFriend = entities.AddFriends.Include("User").Include("User1").Where(u => u.UserName == userName).ToList();
            }
            return listAddFriend;
        }

        public bool IsDuplicateUserAdd(string userName, string userNameAdd)
        {
            bool isSuccess;
            using (DBChatEntities entities = new DBChatEntities())
            {
                // Kiểm tra user name có tồn tại hay không
                isSuccess = entities.AddFriends.Where(u => u.UserName == userName && u.UserNameAdd == userNameAdd).Count() > 0;
            }
            return isSuccess;
        }

    }
}